<?php
/**
 * 抓取入口网址命令
 */
namespace App\Console\Commands;

use Illuminate\Console\Command;

use App\Models\CrawlerUrl;

class CrawlerOriginUrls extends Command
{
    /**
     * The name and signature of the console command.
     *
     * @var string
     */
    protected $signature = 'tx:crawler {domain?}';

    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = '从列表页抓取内容地址';

    /**
     * Create a new command instance.
     *
     * @return void
     */
    public function __construct()
    {
        parent::__construct();
    }

    /**
     * Execute the console command.
     *
     * @return mixed
     */
    public function handle(CrawlerUrl $crawler)
    {
        $this->info("开始抓取任务...");
        if ($domain = $this->argument('domain')) {
            $this->info("抓取网站 {$domain}");
            $res = $crawler->crawlerOriginUrl($domain);
        } else {
            $res = $crawler->crawlerOriginUrl();
        }

        $this->info(json_encode($res));
        $this->info("任务完成！");
    }
}
